/**
 * Created by MADinow on 26.10.2014.
 */

/* -----------------------------------------------------------
 POPUP EVENTS MODULE
 ----------------------------------------------------------- */

define(['ui/popup-ui', 'jquery', 'jquery_ui', 'jquery_session'],
    function (Popup) {

        /**
         * checks whether user is logged in
         * @returns {boolean}
         * @private
         */
        function _isUserLoggedIn(){
            return typeof $.session.get('user') !== "undefined" ;
        }

        /**
         * checks whether user is logged in and opens the
         * corresponding popup window
         * @private
         */
        function _checkForUserSession(){

            setTimeout(function(){
                if (!_isUserLoggedIn())
                    Popup.openPopup(Popup.loginID);
                else
                    Popup.openPopup(Popup.welcomeID);
            }, 1000);

        }

        /**
         * public interface
         */
        return {
            isUserLoggedIn: _isUserLoggedIn,
            checkForUserSession: _checkForUserSession
        }

    }
);
